import { Reducer, Effect, Subscription } from 'umi';
import { getAll } from '@/services/StudentAnalysisCounsellor';
import { getMentorMasterOtherScore } from '@/services/StudentAnalysisStudent';

export type StateType = {
  list?: any[];
};

export type StudentAnalysisCounsellorModelType = {
  namespace: string;
  state: StateType;
  effects: {
    getAllEffects: Effect;
  };
  reducers: {};
  subscriptions: {
    // setup: Subscription;
  };
};

const StudentAnalysisCounsellorModel: StudentAnalysisCounsellorModelType = {
  namespace: 'Model_StudentAnalysisCounsellorModel', //里面存的是state
  state: {
    list: [],
  },
  subscriptions: {},
  effects: {
    *getAllEffects({ payload }: any, { call, put }: any): Generator {
      let token = localStorage.getItem('token');
      const result: any = yield call(getAll, token, payload.data);
      yield put({
        type: 'updateState',
        payload: {
          list: result.data,
        },
      });
      console.log('result.data');
    },
  },
  reducers: {
    //统一格式更新state
    updateState(state: any, action: any) {
      if (!action.payload) {
        return state;
      }
      return {
        ...state,
        ...action.payload,
      };
    },
  },
};

export default StudentAnalysisCounsellorModel;
